<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<title>选择寄回地址</title>
		<meta name="keywords" content="知果汇" />
		<meta name="description" content="知果汇" />
		<link rel="SHORTCUT ICON" href="_IMG_/favicon.ico" />
		<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
		<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
		<style type="text/css">
		    html,body{width: 520px;min-width: 520px;padding: 20px;min-height: 200px;}
		    .noData,.hasData,.mailBox{height: 204px;}
		    /*无数据*/
		    .links{display: inline-block;width: 166px;height: 92px;background: url(/static/web/images/xuanhzong.png) no-repeat;}
			.links01{display: inline-block;width: 166px;height: 92px;background: url(/static/web/images/weixuanzhong1.png) no-repeat;margin-left: 7px;}
			.manageBtn{display: block;color: #C75C5C;font-size: 14px;line-height: 30px;margin-top: 5px;}
			.noData p{display: block;width: 100%;font-size: 15px;color: #333333;}
			.btns{width: 90px;height: 36px;line-height: 36px;text-align: center;display: inline-block;border-radius: 5px;font-size: 14px;}		
			.noData .cancel{color: #FFFFFF;background: #3377C1;margin-left: 215px;margin-top: 15px;}
			.cancel:hover{color: #FFFFFF;}
			/*有数据*/
			.addressItem{width: 128px;height: 66px;padding:12px 18px;font-size: 14px;color: #666666;border:1px solid #E5E5E5;display: inline-block;margin-left: 7px;margin-bottom:5px;}
			.addressItem p{height:38px;margin-bottom: 10px;}
			.ml0{margin-left: 0;}
			.default{border-color:#3377C1;}
			.hasData .cancel{color: #333333;background: #FFFFFF;border:1px solid #E5E5E5;margin-top: 15px;margin-left: 152px;}
			.hasData .cancel:hover{color: #333333;}
			.next{color: #FFFFFF;background: #3377c1;border:1px solid #E5E5E5;margin-top: 15px;margin-left: 40px;}
			.next:hover{color: #FFFFFF;}
			/*上传快递单号*/
			.form-group {margin-bottom: 20px;padding-top: 50px;}
			.form-group label {font-size: 14px;width: 70px;display: inline-block;vertical-align: middle;margin-left: 77px;}
			.form-control {border: 1px solid #E5E5E5;padding: 5px 10px;font-size: 14px;}
			.prev{color: #333333;background: #FFFFFF;border:1px solid #E5E5E5;margin-top: 15px;margin-left: 152px;}
			.prev:hover{color: #333333;}
			.finish{color: #FFFFFF;background: #3377c1;border:1px solid #E5E5E5;margin-top: 15px;margin-left: 40px;}
			.finish:hover{color: #FFFFFF;}
		</style>
	</head>
	<body>
		<div class="steps first">
			<div class="noData hide">
				<a class="links" href="address.html"></a>
				<a class="links01" href="address.html"></a>
				<a class="links01" href="address.html"></a>
				<a class="manageBtn" href="javascript:;">管理收货地址</a>
				<p>暂无寄回地址，请增加收货地址，方便后续邮寄快递。</p>
				<a class="btns cancel" href="javascript:;">取消</a>
			</div>
			<div class="hasData">

				<a class="manageBtn" href="javascript:;">管理收货地址</a>
				<p>请选择收货地址，方便后续邮寄快递。</p>
				<a class="btns cancel" href="javascript:;">取消</a>
				<a class="btns next" href="javascript:;">下一步</a>
			</div>			
		</div>
		<div class="steps second hide">
			<div class="mailBox">
				<div class='form-group'>
					<label>快递单号：</label>
					<input class='form-control' type="number" placeholder="请输入快递单号"/>
				</div>
				<a class="btns prev" href="javascript:;">上一步</a>
				<a class="btns finish" href="javascript:;">完成</a>
			</div>
		</div>
	</body>
	<script src="_JS_/jquery-1.8.3.min.js"></script>
	<script src="_JS_/jquery.base64.js"></script>
	<script src="_JS_/jquery.cookie.js"></script>
	<script src="_JS_/common.js"></script>
	<script src="_P_/layer/layer.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			var url = window.location.href;
			var id=url.split("#")[1];
			var val = $('.addressItem p').text();
			$('.addressItem p').text(cut(val,18));
			var userinfo = $.cookie('userinfo');
			if (userinfo) {
				var user_login = $.base64.decode(userinfo).split(",");
				var uid = user_login[0];
				$.ajax({
					type: "get",
					url: "/index.php/api/form/address_list",
					data: {
						'uid': uid
					},
					dataType: 'jsonp',
					success: function (msg) {
						if (msg.code == 200) {
							if (msg.data == null|| msg.data == '') {
								$('.noData').removeClass('hide');
								$('.hasData').addClass('hide');
							} else {
								$('.noData').addClass('hide');
								$('.hasData').removeClass('hide');
								var len = msg.data.length;
								var html = '';
								for (var i = 0; i < msg.data.length; i++) {
									
									var address = msg.data[i].location.replace(/-/g, " ") + msg.data[i].address;
									var	address01 = cut(address,16);
									if (i == 0) {
										html +='<a class="addressItem default" href="javascript:;" num="' + msg.data[i].id + '">';
									}else{
										html +='<a class="addressItem" href="javascript:;" num="' + msg.data[i].id + '">';
									}
									html +='<p title="'+ address +'">'+ address01 +'</p>';
									html+='<span>'+ msg.data[i].phone + '</span></a>';
								}
								$('.hasData').prepend(html);
							}

						} else if (msg.code == 1000) {
							$('.noData').removeClass('hide');
							$('.hasData').addClass('hide');
						}
						/*地址更换*/
						$('.addressItem').on('click',function(){
							$('.addressItem').removeClass('default');
							$(this).addClass('default');
						});
					}
				});
			} else {
				layer.msg('还未登录！', {icon: 51});
			}
			/*下一步*/
			$('.next').on('click',function(){
				$('.second').removeClass('hide');
				$('.first').addClass('hide');
				try{
					parent.$(".layui-layer-title")[0].innerText = '上传快递单号';
				}catch(e){
					//TODO handle the exception
				}			
			});
			/*上一步*/
			$('.prev').on('click',function(){
				$('.second').addClass('hide');
				$('.first').removeClass('hide');
				try{
					parent.$(".layui-layer-title")[0].innerText = '选择寄回地址';
				}catch(e){
					//TODO handle the exception
				}	
			});
			$('.cancel').on('click',function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
			});

			$('.finish').on('click',function(){
				var num=$('input[type="number"]').val();
				var address=$('.hasData a[class="addressItem default"]').attr('num');
				if(num!=''){
					$.ajax({
						type: "get",
						url: "/index.php/api/form/seller_edit",
						data: {'id': id,
							'status': 6,
							'seller_e':num,
							'address':address},
						dataType: 'jsonp',
						success: function (msg) {
							if (msg.code == 200) {
								parent.order_service(1);
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							}else if (msg.code == 1002) {
								layer.msg(msg.message, {icon: 5});
								parent.order_service(1);
								var desk = parent.layer.getFrameIndex(window.name);
								parent.layer.close(desk);
							}else{
								layer.msg(msg.message, {icon: 5});
							}
						}
					});
				}else{
					layer.msg('不能为空！', {icon: 5});
				}
			})
			$('.manageBtn').on('click',function(){
				window.open('/index.php/index/person/address.html');
			});
		});
	</script>
</html>
